package pers.jphoebe.quartz.exception;

import io.swagger.annotations.Api;
import org.springframework.boot.autoconfigure.web.ErrorController;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import pers.jphoebe.quartz.entity.response.ErrorCode;
import pers.jphoebe.quartz.utils.ResponseDataUtils;
import springfox.documentation.annotations.ApiIgnore;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Created by 蒋时华 on 2017/10/31.
 * 在进入controller前发生异常，比如 404
 */
@RestController
@ApiIgnore
public class ControllerExceptionHandler implements ErrorController {

    @Override
    public String getErrorPath() {
        return "/error";
    }

    @RequestMapping(value = "/error")
    public Object error(HttpServletResponse resp, HttpServletRequest req) {
        // 错误处理逻辑
        return ResponseDataUtils.error(ErrorCode.ERROR_CODE);
    }

}
